
*********************************
*	Author: Rithika Kumar	    *
*   GOAL: Summary Stats 	    *
*   Table 2,A4, A7, A6          *
*********************************


*****************************************************************
*	Set Path to: "JOP Replication files" on your computer       *
*****************************************************************


clear
use "DATA FILES TO SHARE/main_ew_hh_df.dta", clear 

**** BREAK UP OF MIGRANT HUSBAND STATUS ACROSS BOTH YEARS ***** 
net install http://www.stata.com/users/kcrow/tab2xl, replace

keep if year == 0
tab2xl w1_abshusband_dummy w2_abshusband_dummy using "OUTPUT/TABLES/Table_2.xlsx", col(1) row(1)



**** Migration STATS **** 
use "DATA FILES TO SHARE/main_ew_hh_df.dta", clear 
keep if did_sample == 1 & year == 1

est clear 

tabulate NR9, generate(nr_place)

tabulate NR8, generate(nr_state)

gen occup_category = 0 
** Labor categories 94 up are unskilled laborers/ construction/labor 
replace occup_category = 1 if NR11 > 93 & NR11 <= 99
** Lbor nec is code 71 up is skilled labor 
replace occup_category =2 if NR11 > 70 & NR11 <= 93
** Lbor nec is code 60 up is farm labor 
replace occup_category =3 if NR11 > 59 & NR11 <= 68
** Lbor nec is code 50 up is service labor 
replace occup_category =4 if NR11 > 49 & NR11 <= 59
** Lbor nec is code 29 up is clerical and sales
replace occup_category =5 if NR11 > 29 & NR11 <= 49
**  Lbor nec is code 1 up is admin, executive, professional, tecnical
replace occup_category =6 if NR11 > -1 & NR11 <= 29
**
replace occup_category =4 if NR11 > 100 & NR11 <= 115
replace occup_category = . if occup_category == 0
tab occup_category, generate(occup_sep)

label variable nr_place1 "Same village/town"
label variable nr_place2 "Different village/town"
label variable nr_place3 "Another small city"
label variable nr_place4 "Another large city"
label variable occup_sep1 "Unskilled Day Labor"
label variable occup_sep2 "Skilled Labor"
label variable occup_sep3 "Farm Labor"
label variable occup_sep4 "Service Industry"
label variable occup_sep5 "Clerical and Sales"
label variable occup_sep6 "Professional"
label variable NR6 "Age"
label variable nr_state1 "Same State"
label variable nr_state2 "Another State"
label variable nr_state3 "Abroad"
label variable NR10 "Education (years)"
label variable NNR "No. of non-residents"
label variable NR13A "Remittances"

 label define occup_category 0 "non-migrant" 1 "Unskilled Day Labor" 2 "Skilled Labor" 3"Farm" 4"Service Industry" 5"Clerical and Sales" 6"Professional" 7"Other"
label values occup_category occup_category


preserve
keep if w1_abshusband_dummy == 0 & w2_abshusband_dummy == 1

estpost tabstat nr_place1 nr_place2 nr_place3 nr_place4 occup_sep1 occup_sep2 occup_sep3 occup_sep4 occup_sep5 occup_sep6 NR6 nr_state1 nr_state2 nr_state3 NR10 NNR NR13A,c(stat) stat(mean sd min max n) 
esttab using "OUTPUT/TABLES/Table_A7.tex", replace cells("mean(fmt(%13.2fc)) sd(fmt(%13.2fc)) min max count") nonumber  collabels("Mean" "SD" "Min" "Max" "N")  eqlabels("Same village/town" "Different village/town" "Another smalll city" "Another large city" "Unskilled Day Labor" "Skilled Labor" "Farm Labor" "Service Industry" "Clerical and Sales" "Professional" "Age" "Same State" "Another State" "Abroad" "Education (years)" "No. of non-residents" "Remittances") label


restore



**** HOUSEHOLD CHARACTERSTICS  ***** 

use "DATA FILES TO SHARE/main_ew_hh_df.dta", clear 
tab ID14, generate(occup)
tab HQ1, generate (hh_type)
tab FM1, gen(farmland)

egen mig_year = group(mig_husb year)
est clear


table year mig_husb, stat(mean farmland2  FM11 AN1  INCCROP INCANIMAL INCAG INCBUSINESS INCOTHER ///
 INCSALARY INCOME INCAGLAB ASSETS5 NF1 RC1 NNR NPERSONS NADULTM NADULTF HHLITERATE ///
 occup1 occup2 occup3 occup4 occup5 occup6 occup7 occup8 occup9 occup10 occup11 ///
) nototals 

 

collect export "OUTPUT/TABLES/Table_A6.html", replace
 
 
*** NOTE THAT THIS OUTPUT FORMAT IS SLIGHTLY DIFFERENT FROM WHAT I HAVE IN THE LATEX FILE which I customized manually to display each variable for both waves together. Right now you will see all outputs for year == 0 first and then year == 1. 
 
 
 
 ****** Sumamry Stats on DV in IHDS *****
 
 keep if did_sample ==1

 collapse (mean) ///
 mob_mean = mob_score_norm ///
 dec_mean =  dec_score_norm /// 
 cash_mean = GR_hh_cash ///
 pol_mean = pol_score_norm ///
 (sd) ///
  mob_sd = mob_score_norm ///
 dec_sd = dec_score_norm ///
 cash_sd = GR_hh_cash ///
 pol_sd = pol_score_norm, by(year w2_abshusband_dummy) 
 
 foreach i in mob dec cash pol {
 	 format `i'_mean %9.2f
 	 format `i'_sd %9.2f

 }
 
 reshape long mob_ dec_ cash_ pol_, i(year w2_abshusband_dummy) j(stat) string
  reshape wide mob_ dec_ cash_ pol_, i(year stat) j(w2_abshusband_dummy) 
  
  preserve
  keep pol_0 pol_1 stat year
  gen variable = "Political index" 
  rename (pol_0 pol_1) (non_migrant migrant)
  tempfile pol
    save `pol'
restore
  


preserve
  keep dec_0 dec_1 stat year
  gen variable = "Bargaining Power" 
  rename (dec_0 dec_1) (non_migrant migrant)
  tempfile dec
  save `dec'
restore

preserve
  keep cash_0 cash_1 stat year
  gen variable = "Access to Cash" 
  rename (cash_0 cash_1) (non_migrant migrant)
  tempfile cash
  save `cash'
restore


  keep mob_0 mob_1 stat year
  gen variable = "Autonomy over Mobility" 
  rename (mob_0 mob_1) (non_migrant migrant)
  tempfile mob
  save `mob'

  append using `dec'
  append using `cash'
  append using `pol'
  
  
gen wave = "2005-06" if year == 0
replace wave = "2011-12" if year == 1
drop year

 

order variable 
order wave, after (variable)
order migrant, after (stat)

 export excel using "OUTPUT/TABLES/Table_A4.xls", firstrow(variables) replace

		
		
	